import { Pipe, PipeTransform } from '@angular/core';


/**
 * 数据管道
 * @export
 * @class DataWalletPipe
 * @implements {PipeTransform}
 */
@Pipe({
  name: 'dataWallet',
})
export class DataWalletPipe implements PipeTransform {
  /**
   * Takes a value and makes it lowercase.
   */
  transform(value: string, ...args) {
    return this.dataBase(value, ...args);
  }

  dataBase(value, ...args) {
    
    // debugger

    let str;
    let arg = args[0];
    switch (arg) {
      case "BillDirec":
        str = this.yuemxData(value, arg);
        break;
      case "Pattern":
        str = this.Pattern(value);
        break;
      case "PatternIMg":
        str = this.PatternIMg(value);
        break;
      case "State":
        str = this.State(value);
        break;
      case "Classify":
        str = this.Classify(value);
        break;
      case "isUserId":
        str = this.isUserId(value);
        break;

    }
    return str;
  }
  /**
   * 余额明细
   */
  yuemxData(Direction, arg) {
    if (Direction == 1) {
      Direction = "开通会员";
    } else if (Direction == 2) {
      Direction = "打赏";
    } else if (Direction == 3) {
      Direction = "转余额";
    } else if (Direction == 4) {
      Direction = "动态分享奖励";
    } else if (Direction == 5) {
      Direction = "动态获取红包";
    } else {
      Direction = "";
    }
    return Direction;
  }

  /**
   * 模式
   * @param Pattern 
   */
  Pattern(Pattern) {

    let type = "";
    if (Pattern == 10) {
      type = "单人";
    } else if (Pattern == 20) {
      type = "对战";
    } else if (Pattern == 30) {
      type = "多人";
    } else if (Pattern == 0) {
      type = "未设置";
    }
    return type;
  }

  PatternIMg(Pattern) {
    // debugger
    let type = "";
    if (Pattern == 10) {
      type = "assets/imgs/img/one.png";
    } else if (Pattern == 20) {
      type = "assets/imgs/img/two.png";
    } else {
      type = "assets/imgs/img/more.png";
    }
    return type;
  }


  State(key) {
    let str = "";
    switch (key) {
      case 10:
        str = "已参与";
        break;
      case 20:
        str = "进行中";
        break;
      default:
        str = "已结束";
        break;
    }
    return str;
  }


  /**
   * 挑战类型
   * @param type 
   */
  Classify(type) {
    let str = "";
    if (type == 10) {
      str = "健身";
    } else if (type == 20) {
      str = "健脑";
    } else if (type == 30) {
      str = "健财";
    } else if (type == 40) {
      str = "健心";
    }
    return str;
  }

  isUserId(type) {
    let isok = false;
    let UserInfo = eval("(" + localStorage.getItem("User") + ")");
    if (type == UserInfo.UserID) {
      isok = true;
    }
    return isok;
  }


  isok(key, data) {
    let fenxiang = false;
    let list2 = false;
    let edit = false;
    let del = false;
    let tuichu = false;
    if (!(this.isUserId(data.UserID))) {
      return false;
    }
    if (data.State == 10) {
      list2 = true;
      //分享
      fenxiang = true;
      //编辑
      edit = true;
      if (data.joinlist.length < 2) {
        //删除
        del = true;
      }
    } else if (data.State == 20) {
      //分享
      fenxiang = true;
      //退出
      tuichu = true;
    } else {
      //分享
      fenxiang = true;
    }
    let isok = false;
    switch (key) {
      case "fenxiang":
        isok = fenxiang;
        break;
      case "list2":
        isok = list2;
        break;
      case "edit":
        isok = edit;
        break;
      case "del":
        isok = del;
        break;
      case "tuichu":
        isok = tuichu;
        break;
    }
    return isok;
  }

}
